<script type="text/javascript" src="/admins/js/jquery/jquery.PrintArea.js"></script>
<div style="margin-left: 50px;margin-top: 20px;">
<div id="xz" style="margin-bottom: 20px;">
    运送方式：
     <select id="xzys" name="xzys" onchange="javascript:xz()">
        <?php $num = 0;
            foreach ($this->agentcomp as $key => $agentcomp) { ?>
            <option value="<?php echo $agentcomp->id; ?>"><?php echo $agentcomp->name; ?></option>
        <?php 
            $num = $num>$agentcomp->id?$num:$agentcomp->id;
            } 
        ?>
    </select>
    <input type="hidden" id="num" name="num" value="<?php echo $num;?>" />
</div>
    <style>
        body{
            -webkit-print-color-adjust: exact;
        }
        table tr {
            border-bottom: 1px #ddd solid;
            height: 36px;
        }
		.fss{width: 750px;margin-right: 10px;margin-top: 20px;}
    </style>
<div>
<?php foreach ($this->agentcomp as $key => $agentcomp) { ?>
    <div id="fs<?php echo $agentcomp->id;?>" <?php echo $key == 0 ? 'style="display:block;"' : 'style="display:none;"'; ?> class="fss">
        <style>
            body{
                -webkit-print-color-adjust: exact;
                font-size: 14px;
            }
        </style>
        <?php if($agentcomp->id != Application_Model_AgentCompany::Agent_SY){?>
        <div class="addcontent">
            <table width="750" border="0" cellpadding="0" cellspacing="0" style="margin-left: 10px;margin-right: 10px;margin-top: 20px;">
              <tr>
                  <td colspan="8" align="center" style="font-size:24px;font-weight: 900;height: 50px;">
                      <?php echo $agentcomp->Id== Application_Model_AgentCompany::Agent_4px?"递四方快件交货清单":$agentcomp->name.$agentcomp->username; ?>
                  </td>
              </tr>
              <?php if($agentcomp->Id== Application_Model_AgentCompany::Agent_4px){ ?>
                    <tr>
                        <td colspan="6">客户代码：<?php echo $agentcomp->username;?></td>
                        <td colspan="2" align="right">交货日期：<?php echo date("m月d日");?></td>
                    </tr>
              <?php } ?>
              <tr align="center">
                  <td width="50">&nbsp;</td>
                  <td width="180">出库单号</td>
                  <td width="50">数量</td>
                  <td width="50">国家</td>
                  <td width="80">重量(kg)</td>
                  <td width="100">体积</td>
                  <td width="160">渠道</td>
                  <td width="80"><?php echo $agentcomp->Id== Application_Model_AgentCompany::Agent_4px?"类型":"日期"; ?></td>
                </tr>
                <?php $i = 0;$num = 0;$sumWeight =0;
                    if($agentcomp->BillAll){
                        foreach ($agentcomp->BillAll as $key => $billVal) {
                            $firstWeight = Application_Model_WayWeight::getWeightByType($billVal->id,Application_Model_WeightType::FirstWeight);
//                            $firstVloume = Application_Model_WayWeight::getWeightByType($billVal->id,Application_Model_WeightType::FirstVolume);
                            $volumLog = Application_Model_WayLog::getByWayIdInteriorType($billVal->id, Application_Model_WayLog::Type_BillVolume);
                            $channelLog = Application_Model_WayLog::getByWayIdInteriorType($billVal->id, Application_Model_WayLog::Type_BillAffirmChannel); 
                            $num += count($billVal->SplitWeight)<=1?1:count($billVal->SplitWeight);
                            $splitWeight = $billVal->SplitWeight;
							$sumWeight += $firstWeight?$firstWeight->weight/1000:0;
                    ?>
                    <tr style="border-bottom: 1px #ccc solid;">
                        <td align="center"><?php echo ++$i;?></td>
                        <td align="center"><?php echo $billVal->agentNo;?></td>
                        <td align="center"><?php echo count($splitWeight)<=1?1:count($billVal->SplitWeight);?></td>
                        <td align="center"><?php echo $billVal->UserCity?$billVal->UserCity->word:"";?></td>
                        <td align="center"><?php echo $firstWeight?$firstWeight->weight/1000:0; ?></td>
                        <td align="center"><?php echo count($splitWeight)<=1?$splitWeight[0]->Length."*".$splitWeight[0]->Width."*".$splitWeight[0]->Height:"";?></td>
                        <td align="center"><?php echo $channelLog?$channelLog->DescriptionByChannel->name:($billVal->channelname?$billVal->channelname->name:"暂无");?></td>
                        <td align="center"><?php echo $agentcomp->Id== Application_Model_AgentCompany::Agent_4px?"包裹":date("m月d日");?></td>
                    </tr>
                    <?php if(count($splitWeight)>1){ ?>
                        <?php foreach ($splitWeight as $key => $splitVal) { ?>
                            <tr <?php echo ($key+1)==count($splitWeight)?"":'style="border-bottom:none;"'; ?>>
                                <td align="center"></td>
                                <td align="center"></td>
                                <td align="center"><?php echo ($key+1)."/".count($billVal->SplitWeight);?></td>
                                <td align="center"></td>
                                <td align="center"><?php echo $splitVal->Weight/1000; ?></td>
                                <td align="center"><?php echo $splitVal->Length."*".$splitVal->Width."*".$splitVal->Height;?></td>
                                <td align="center"></td>
                                <td align="center"></td>
                            </tr>
                        <?php } ?>
                    <?php } ?>
                <?php } }
                    if($agentcomp->EditBillAll){
                        foreach ($agentcomp->EditBillAll as $key => $billVal) {
                            $firstWeight = Application_Model_WayWeight::getWeightByType($billVal->id,Application_Model_WeightType::FirstWeight);
                            $volumLog = Application_Model_WayLog::getByWayIdInteriorType($billVal->id, Application_Model_WayLog::Type_BillVolume);
                            $channelLog = Application_Model_WayLog::getByWayIdInteriorType($billVal->id, Application_Model_WayLog::Type_BillAffirmChannel); 
                ?>
                    <tr style="border-bottom: 1px #ccc solid;">
                        <td align="center"><?php echo $i++;?></td>
                        <td align="center"><?php echo $billVal->agentNo;?></td>
                        <td align="center">1</td>
                        <td align="center"><?php echo $billVal->UserCity?$billVal->UserCity->word:"";?></td>
                        <td align="center"><?php echo $firstWeight?$firstWeight->weight/1000:0; ?></td>
                        <td align="center"><?php echo $volumLog?($volumLog->description != "**"?$volumLog->description:""):"";?></td>
                        <td align="center"><?php echo $channelLog?$channelLog->DescriptionByChannel->name:($billVal->channelname?$billVal->channelname->name:"暂无");?></td>
                        <td align="center"><?php echo date("m月d日");?></td>
                    </tr>
               <?php } } ?>
          </table>
        </div>
        <?php } else { ?>
        <div class="addcontent">
            <table width="800" border="0" cellpadding="0" cellspacing="0" style="margin-left: 10px;margin-right: 10px;margin-top: 20px;">
              <tr>
                  <td colspan="8" align="center" style="font-size:24px;font-weight: 900;height: 50px;">
                      <?php echo $agentcomp->name.$agentcomp->username; ?>
                  </td>
              </tr>
              <tr align="center">
                  <td width="50">&nbsp;</td>
                  <td width="180">出库单号</td>
                  <td width="50">属性</td>
                  <td width="50">数量</td>
                  <td width="50">国家</td>
                  <td width="80">重量(kg)</td>
                  <td width="100">体积</td>
                  <td width="160">渠道</td>
                  <td width="80">日期</td>
                </tr>
                <?php $i = 0;$num = 0;$sumWeight =0;
                    if($agentcomp->BillAll){
                        foreach ($agentcomp->BillAll as $key => $billVal) {
                            $firstWeight = Application_Model_WayWeight::getWeightByType($billVal->id,Application_Model_WeightType::FirstWeight);
                            $shangyiLog = Application_Model_WayLog::getByWayIdInteriorType($billVal->id, Application_Model_WayLog::Type_PropertySY);
                            $volumLog = Application_Model_WayLog::getByWayIdInteriorType($billVal->id, Application_Model_WayLog::Type_BillVolume);
                            $channelLog = Application_Model_WayLog::getByWayIdInteriorType($billVal->id, Application_Model_WayLog::Type_BillAffirmChannel); 
                            $num += count($billVal->SplitWeight)<=1?1:count($billVal->SplitWeight);
                            $splitWeight = $billVal->SplitWeight;
							$sumWeight += $firstWeight?$firstWeight->weight/1000:0;
                    ?>
                    <tr style="border-bottom: 1px #ccc solid;">
                        <td align="center"><?php echo ++$i;?></td>
                        <td align="center"><?php echo $billVal->agentNo;?></td>
                        <td align="center"><?php echo $shangyiLog?$shangyiLog->description:"";?></td>
                        <td align="center"><?php echo count($splitWeight)<=1?1:count($billVal->SplitWeight);?></td>
                        <td align="center"><?php echo $billVal->UserCity?$billVal->UserCity->word:"";?></td>
                        <td align="center"><?php echo $firstWeight?$firstWeight->weight/1000:0; ?></td>
                        <td align="center"><?php echo count($splitWeight)<=1?$splitWeight[0]->Length."*".$splitWeight[0]->Width."*".$splitWeight[0]->Height:"";?></td>
                        <td align="center"><?php echo $channelLog?$channelLog->DescriptionByChannel->name:($billVal->channelname?$billVal->channelname->name:"暂无");?></td>
                        <td align="center"><?php echo date("m月d日");?></td>
                    </tr>
                    <?php if(count($splitWeight)>1){ ?>
                        <?php foreach ($splitWeight as $key => $splitVal) { ?>
                            <tr <?php echo ($key+1)==count($splitWeight)?"":'style="border-bottom:none;"'; ?>>
                                <td align="center"></td>
                                <td align="center"></td>
                                <td align="center"></td>
                                <td align="center"><?php echo ($key+1)."/".count($billVal->SplitWeight);?></td>
                                <td align="center"></td>
                                <td align="center"><?php echo $splitVal->Weight/1000; ?></td>
                                <td align="center"><?php echo $splitVal->Length."*".$splitVal->Width."*".$splitVal->Height;?></td>
                                <td align="center"></td>
                                <td align="center"></td>
                            </tr>
                        <?php } ?>
                    <?php } ?>
                <?php } }
                    if($agentcomp->EditBillAll){
                        foreach ($agentcomp->EditBillAll as $key => $billVal) {
                            $firstWeight = Application_Model_WayWeight::getWeightByType($billVal->id,Application_Model_WeightType::FirstWeight);
                            $volumLog = Application_Model_WayLog::getByWayIdInteriorType($billVal->id, Application_Model_WayLog::Type_BillVolume);
                            $shangyiLog = Application_Model_WayLog::getByWayIdInteriorType($billVal->id, Application_Model_WayLog::Type_PropertySY);
                            $channelLog = Application_Model_WayLog::getByWayIdInteriorType($billVal->id, Application_Model_WayLog::Type_BillAffirmChannel); 
                ?>
                    <tr style="border-bottom: 1px #ccc solid;">
                        <td align="center"><?php echo $i++;?></td>
                        <td align="center"><?php echo $billVal->agentNo;?></td>
                        <td align="center"><?php echo $shangyiLog?$shangyiLog->description:"";?></td>
                        <td align="center">1</td>
                        <td align="center"><?php echo $billVal->UserCity?$billVal->UserCity->word:"";?></td>
                        <td align="center"><?php echo $firstWeight?$firstWeight->weight/1000:0; ?></td>
                        <td align="center"><?php echo $volumLog?($volumLog->description != "**"?$volumLog->description:""):"";?></td>
                        <td align="center"><?php echo $channelLog?$channelLog->DescriptionByChannel->name:($billVal->channelname?$billVal->channelname->name:"暂无");?></td>
                        <td align="center"><?php echo date("m月d日");?></td>
                    </tr>
               <?php } } ?>
          </table>
        </div>
        <?php } ?>
        <div style="margin-top: 30px; text-align:right;">
            一共有运单：<span style="margin-right:30px;font-size: 16px;font-weight: 900;"><?php echo $i;?></span>
            一共重量数：<span style="margin-right:30px;font-size: 16px;font-weight: 900;"><?php echo $sumWeight>0?$sumWeight:0;?></span>            
            一共包裹数：<span style="margin-right:30px;font-size: 16px;font-weight: 900;"><?php echo $num;?></span>
        </div>
    </div>
<?php }?>  
</div>
<div style='padding-top:10px;padding-bottom: 5px;padding-left: 20px;float: left;width: 90%' id="div_button">
        <input type="button" id="refo" naem="refo" value="返回" style="background-color: #1668A4;width: 80px;height: 30px;color: white;font-size: 14px;border-radius:8px;"/>
        <input type="button" id="print" naem="print" value="打印" style="background-color: #FF8312;width: 80px;height: 30px;color: white;font-size: 14px;border-radius:8px;margin-left: 250px;"/>
    </div>
</div>
<script type="text/javascript">
    $("#refo").click(function(){
        location.href = "/admini/managewaybill/index/stus/<?php echo Application_Model_wayBillItem::Interior_AffirmChannel;?>"; 
    });
    $('#div_button #print').click(function(){
        var fs = $('#xzys').val();
        $("#fs"+fs).printArea(); 
        //$("#fs"+fs+" div.addcontent").printArea(); 
    });
    function xz()
    {
        var num = $("#num").val();
        for(var i = 0;i<=num;i++){
            $('#fs'+i).hide();
        }
        var val = $('#xzys').val();
        $('#fs'+val).show();
    }
</script>